package com.hp.java08_springboot.controller;

import com.hp.java08_springboot.pojo.Car;
import com.hp.java08_springboot.pojo.Driver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Arrays;
import java.util.List;

@Controller
public class HelloController {

    @Autowired
    private Driver driver;

    @RequestMapping("hello")
    public String hello(Model model){
        model.addAttribute("msg","Hello Thymeleaf!!");
        model.addAttribute("driver",driver);
        List<Car> cars = Arrays.asList(new Car("001", "benz", "red"),
                new Car("002", "bmw", "green"),
                new Car("003", "audi", "black"));
        model.addAttribute("cars",cars);
        return "hello";
    }

    @RequestMapping("show")
    public String show(String name,Model model){
        model.addAttribute("name",name);
        return "show";
    }
}
